package club.kingyin.easycache.method.core;

import club.kingyin.easycache.cache.CacheAdapter;
import club.kingyin.easycache.cache.ValueSerializer;
import club.kingyin.easycache.key.InvokePostProcess;
import club.kingyin.easycache.proxy.PointEasyCache;
import club.kingyin.easycache.proxy.adapter.CacheMethodKeyAdapter;
import org.aspectj.lang.ProceedingJoinPoint;

public class PointEasyCacheEnhancer extends DefaultCacheEnhancer{

    @Override
    protected void init() {
        super.init();
    }

    private PointEasyCache cache = null;

    private CacheMethodKeyAdapter cacheMethodKeyAdapter = null;

    public void setCacheMethodKeyAdapter(CacheMethodKeyAdapter cacheMethodKeyAdapter) {
        this.cacheMethodKeyAdapter = cacheMethodKeyAdapter;
    }

    public PointEasyCacheEnhancer(CacheAdapter cacheAdapter, ValueSerializer serializer) {
        super(cacheAdapter, serializer);
    }

    public PointEasyCacheEnhancer(String path, ValueSerializer serializer) {
        super(path, serializer);
    }

    public PointEasyCacheEnhancer(String path) {
        super(path);
    }

    public PointEasyCacheEnhancer(CacheAdapter cacheAdapter) {
        super(cacheAdapter);
    }

    public PointEasyCacheEnhancer() {
        super();
    }

    public Object proceed(ProceedingJoinPoint target) {
        if (cache == null) {
            cache = new PointEasyCache(this, cacheMethodKeyAdapter);
            cache.setInvokePostProcesses(getInvokePostProcessor()==null?new InvokePostProcess[0]:getInvokePostProcessor());
        }
        return cache.odInvoke(target);
    }

}
